///////////////////////////////////////////////
// This file is part of NoLifeStory.         //
// Please see Global.h for more information. //
///////////////////////////////////////////////
#include "Global.h"

////////////////////////////////////////////////////////////////
// Welcome to NoLifeStory!
////////////////////////////////////////////////////////////////

int main(int argc, char **argv) {//Not much to do here
	try {
#ifdef NLS_WINDOWS
		SetConsoleTitleA("NoLifeStory::Console");
#endif
		cout << "Loading NoLifeStory" << endl;

#ifdef ONLINE
		//ns = new NetworkSession("98.228.228.210", 8484);//Bui's vana server
		ns = new NetworkSession("63.251.217.2", 8484);//Official server
		//ns = new NetworkSession("83.80.149.209", 8484);//Diaserver!

		// create thread.
#ifdef NLS_WINDOWS
		DWORD dwThreadId;
		if (CreateThread(NULL, 0, NetworkSession::CreateReceiveThread, ns, 0, &dwThreadId) == NULL) {
			cout << "Could not create thread D:!" << endl;
		} else {
			cout << "Created thread " << dwThreadId << endl;
		}
#else

		// Make thread code here for unix and such (maybe we should use zthread, boost or something else?)
#endif
#endif

		string* strs = new string[argc];
		for (auto i = 0; i < argc; i++) {
			strs[i] = argv[i];
		}

		Game::init(strs, argc);
		while (Game::loop()) {
			//SDL_Delay(10); // Hahah, sleep that mfckr!
		}
		Game::unload();
		
	} catch (exception ex) {
		cout << "Exception! " << ex.what() << endl;
		getchar();
		cin.get();
#ifdef ONLINE
		return WSAGetLastError();
#else
		return 1;
#endif
	}
	return 0;
}